<template>
  <div class="container">
    <div class="balance-list">
      <div
        v-for="item in balanceList"
        class="balance-cell with-grey-bottom-border"
      >
        <div class="left">
          <div class="type">{{ item.annotation }}</div>
          <div class="time">{{ item.created_at }}</div>
        </div>
        <div class="right">{{ item.type === 1 ? "+" : "-" }} {{ item.money }}</div>
      </div>
    </div>
    <load-more @loadMore="loadMore"></load-more>
  </div>
</template>

<script>
import loadMore from "@/components/load-more";
import { getBalanceDetail } from "@/api/vip";
export default {
  data() {
    return {
      balanceList: [],
      isAll: false,
      loading: false,
      page:1
    };
  },
  methods: {
    getBalanceDetail(page) {
      getBalanceDetail({ page }).then(res => {
        if (res.status === 200) {
          this.balanceList.push(...res.data.data);
          if (res.data.data.length === 0) {
            this.isAll = true;
            this.$dialog.toast({
              mes: "已经到最底了",
              timeout: 1000
            });
          }
        }
      });
    },
    loadMore() {
      if (this.loading || this.isAll || this.balanceList.length === 0) return;
      this.loading = true;
      this.getBalanceDetail(++this.page);
    }
  },
  created() {
    this.getBalanceDetail(1);
  },
  components: {
    loadMore
  }
};
</script>

<style lang="less" scoped>
.container {
  height: auto;
  min-height: 100%;
  .balance-list {
    margin-top: 0.48rem;
    .balance-cell {
      background: #fff;
      display: flex;
      justify-content: space-between;
      padding: 0 3.2%;
      height: 2.4rem;
      .left {
        .type {
          font-size: 0.58rem;
          color: #444444;
          padding: 0.4rem 0 0.3rem;
        }
        .time {
          color: #999999;
          font-size: 0.48rem;
        }
      }
      .right {
        font-size: 0.72rem;
        font-weight: bold;
        color: #f85859;
        line-height: 2.4rem;
      }
    }
  }
}
</style>
